package com.example.demo.leetcode.top;


import javax.xml.soap.Node;
import java.util.ArrayList;
import java.util.List;

/**
 * 环形链表
 */
public class CircleTest {


    public ListNode detectCycle(ListNode head) {

        List<ListNode> list = new ArrayList<>();
        while(head != null){
            if(!list.contains(head)){
                list.add(head);
                head = head.next;
            }else{
                return head;
            }
        }
        return null;
    }



    public static void main(String[] args) {


    }

    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
